package com.qdevelop.model.utils.basesuport;

import java.io.File;

public class RootPath {
	private String root;
	public String getRootPath(){
		String path = this.getClass().getClassLoader().getResource("").getPath().replaceAll("^/|build/classes/|WEB-INF/classes/", "");
		 getWebInf(new File(path));
		return root.replaceAll("\\\\", "/")+"/";
	}
	
	private void getWebInf(File pf){
		File[] files = pf.listFiles();
		for( File f : files){
			if(f.isDirectory()){				
				if(f.getName().equals("WEB-INF")){
					root = f.getParent();
					break;
				}else if(f.getName().equals("WebRoot")||f.getName().equals("WebContent")){
					getWebInf(f);
				}
			}
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(new RootPath().getRootPath());
	}

}
